package com.ruoyi.project.pro.texture.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.pro.texture.domain.ProTexture;
import com.ruoyi.project.pro.texture.mapper.TextureMapper;
import com.ruoyi.project.pro.texture.service.ITextureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: zhizun
 * @author: Mrs.ye
 * @create: 2020-09-17 14:21
 * @description:
 **/
@Service
public class TextureServiceImpl implements ITextureService {

    @Autowired
    private TextureMapper textureMapper;
    /**
     * 分页查询产品风格
     * @return
     */
    @Override
    public List<ProTexture> selectTexture(ProTexture proTexture) {
        return textureMapper.selectTextureList(proTexture);
    }


    /**
     * 校验岗位名称是否唯一
     *
     * @param proTexture 产品风格信息
     * @return 结果
     * 根据公告的名字到数据库中查询公告
     * 将数据库中公告的id传进来的公告id进行对比
     */
    @Override
    public String checkTextureNameUnique(ProTexture proTexture) {
        Long textureId = StringUtils.isNull(proTexture.getTextureId()) ? -1L : proTexture.getTextureId();
        ProTexture info = textureMapper.checkTextureNameUnique(proTexture.getTextureName());
        //如果根据公告名称查询出来了公告,并且查询出来的公告id和原本的id不同,表示同一个公告名称有不同的id,
        //反过来就是说不同的id相同的公告名称,这样公告名称就不唯一了
        if (StringUtils.isNotNull(info) && info.getTextureId().longValue() != textureId.longValue())
        {
            return UserConstants.TYPE_CODE_NOT_UNIQUE;
        }
        return UserConstants.TYPE_CODE_UNIQUE;
    }

    /**
     * 新增产品风格
     * @param proTexture
     * @return
     */
    @Override
    public int insertProTexture(ProTexture proTexture) {
        proTexture.setCreateBy(ShiroUtils.getLoginName());
        return textureMapper.insertProTexture(proTexture);
    }

    /**
     * 通过id查询产品风格
     * @param textureId
     * @return
     */
    @Override
    public ProTexture selectTextureById(Long textureId) {
        ProTexture proTexture = textureMapper.selectTextureById(textureId);
        System.out.println(proTexture);

        return proTexture;
    }

    /**
     * 修改产品风格
     * @param proTexture
     * @return
     */

    @Override
    public int updateTexture(ProTexture proTexture) {
        proTexture.setUpdateBy(ShiroUtils.getLoginName());
        return textureMapper.updateTexture(proTexture);
    }

    @Override
    public int removeProTextureById(Long[] ids) {

        return textureMapper.removeProTextureById(ids);
    }
}
